<?php

namespace apps\marriage\app\op\controller;

use apps\marriage\core\service\MarketingActivityJoinerService;
use apps\marriage\core\service\UserService;
use think\Request;

class MarketingActivityJoinerController extends BaseMarriageOpController
{
    /**
     * @var MarketingActivityJoinerService
     */
    private $marketingActivityJoinerService;

    /**
     * @var UserService
     */
    private $userService;

    protected function init()
    {
        parent::init();
        $this->marketingActivityJoinerService = service('MarketingActivityJoiner', SERVICE_NAMESPACE);
        $this->userService = service('User', SERVICE_NAMESPACE);
    }

    public function lists(Request $request)
    {
        $pageSize = $request->param('page_size', 10, 'intval');
        $activityId = $request->param('activity_id', 0, 'intval');
        $params = [
            'activity_id' => $activityId
        ];
        $res = $this->marketingActivityJoinerService->pageListByParams($params, $pageSize);
        foreach ($res['data'] as &$rs) {
            $user = $this->userService->getByPk($rs['user_id']);
            $user = arrayOnly($user, ['id', 'nick', 'avatar_url']);
            $rs['user'] = $user;
        }
        return $this->success($res);
    }
}